﻿var id = getUrlParam("id");
var jsondata;
$(function () {
    var id = getUrlParam("id");
    $.ajax({
        url: '/Flow/GetFlowId',
        type: 'post',
        dataType: 'json',
        async: false,
        data: {
            id: id
        },
        success: function (d) {
            jsondata = d.data[0].content;
        }
    });
});
var property = {
    width: 1072,
    height: 600,
    toolBtns: ["start round", "end round", "task round", "node", "chat", "state", "plug", "join", "fork", "complex mix"],
    haveHead: false,
    headBtns: ["new", "open", "save", "undo", "redo", "reload"],//如果haveHead=true，则定义HEAD区的按钮
    haveTool: false,
    haveGroup: true,
    useOperStack: true
};
var remark = {
    cursor: "选择指针",
    direct: "结点连线",
    start: "入口结点",
    "end": "结束结点",
    "task": "任务结点",
    node: "自动结点",
    chat: "决策结点",
    state: "状态结点",
    plug: "附加插件",
    fork: "分支结点",
    "join": "联合结点",
    "complex mix": "复合结点",
    group: "组织划分框编辑开关"
};
var demo;
$(document).ready(function () {
    demo = $.createGooFlow($("#demo"), property);
    demo.setNodeRemarks(remark);
    demo.onItemDel = function (id, type) {
        if (confirm("确定要删除该单元吗?")) {
            this.blurItem();
            return true;
        } else {
            return false;
        }
    }
    demo.loadData(JSON.parse(jsondata));
    var json = JSON.parse(jsondata);
    var tipHtml =
        '<div style="position:absolute;left:10px;margin-top: 10px;padding:10px;border-radius:5px;background:rgba(0,0,0,0.05);z-index:1000;display:inline-block;">';
    tipHtml +=
        '<div style="display: inline-block;"><i style="padding-right:5px;color:#5FB878;" class="layui-icon">&#xe612;</i><span>已处理</span></div>';
    tipHtml +=
        '<div style="display: inline-block;margin-left: 10px;"><i style="padding-right:5px;color:#5bc0de;" class="layui-icon">&#xe612;</i><span>正在处理</span></div>';
    tipHtml +=
        '<div style="display: inline-block;margin-left: 10px;"><i style="padding-right:5px;color:#d9534f;" class="layui-icon">&#xe612;</i><span>不通过</span></div>';
    tipHtml +=
        '<div style="display: inline-block;margin-left: 10px;"><i style="padding-right:5px;color:#f0ad4e;" class="layui-icon">&#xe612;</i><span>驳回</span></div>';
    tipHtml +=
        '<div style="display: inline-block;margin-left: 10px;"><i style="padding-right:5px;color:#999;" class="layui-icon">&#xe612;</i><span>未处理</span></div></div>';
    $("#demo").append(tipHtml);
    $.each(json.nodes,
        function (i, item) {
            if (item.type == "start round") {
                $("#" + i).css("background-color", "#5FB878");
            }
            else {
                if (item.type === "end round") {

                }
                else {
                    var setNodeApproval = JSON.parse(item.setNodeApproval);
                    if (setNodeApproval.ApprovalStatu === "0") {
                        $("#" + i).css("background-color", "#5bc0de");
                    }
                    if (setNodeApproval.ApprovalStatu === "1") {
                        $("#" + i).css("background-color", "#5FB878");
                    }
                    if (setNodeApproval.ApprovalStatu === "2") {
                        $("#" + i).css("background-color", "#d9534f");
                    }
                    if (setNodeApproval.ApprovalStatu === "3") {
                        $("#" + i).css("background-color", "#f0ad4e");
                    }
                }
            }

        }
    )
    //$("#1529474768429").css("background-color", "#5FB878");
    //$("#1528855740178").css("background-color", "#5FB878");
});
